<template>
  <div>
    <Breadcrumbs :breadtitle="{ '1': '订单管理', '2': '订单列表' }"></Breadcrumbs>
    <el-card>
      <!-- 输入添加 -->
      <el-row :gutter="20" type="flex" justify="end">
        <el-col :span="8" :pull="1">
          <div>
            <el-input placeholder="请输入内容" @clear="getOrders" clearable v-model="queryInfo.query">
              <el-button slot="append" icon="el-icon-search" @click="getOrders()"></el-button>
            </el-input>
          </div>
        </el-col>
      </el-row>

      <!-- 表格 -->
      <el-table :data="OrdersList" border style="width: 100%" stripe>
        <el-table-column align="center" type="index" label="序号" width="50">
        </el-table-column>
        <el-table-column prop="order_number" label="订单编号" width="220">
        </el-table-column>
        <el-table-column prop="order_price" label="订单价格"> </el-table-column>
        <el-table-column prop="email" label="是否付款">
          <template slot-scope="scope">
            <el-tag size="mini" type="danger" v-if="scope.row.pay_status == 0">未付款</el-tag>
            <el-tag size="mini" v-else-if="scope.row.pay_status == 1">已付款</el-tag>
          </template>
        </el-table-column>
        <el-table-column prop="is_send" label="是否发送"> </el-table-column>
        <el-table-column label="下单时间" width="150">
          <template slot-scope="scope">
            <span>{{scope.row.update_time|times('hours')}}</span>
          </template>
        </el-table-column>
        <el-table-column prop="address" label="操作">
          <template>
            <el-button size="mini" type="primary" @click="dialogdizhi=true">编辑</el-button>
            <el-button size="mini" type="success" @click="BtnWuliu()">物流</el-button>
          </template>
        </el-table-column>
      </el-table>

      <!-- 分页 -->
      <el-pagination :page-sizes="[1, 2, 5, 7]" :page-size="queryInfo.pagesize" :current-page="queryInfo.pagenum" :total="total" layout="total, sizes, prev, pager, next, jumper" @size-change="handleSizeChange" @current-change="handleCurrentChange">
      </el-pagination>
    </el-card>

    <!-- 编辑地址对话框 -->
    <el-dialog title="修改地址" :visible.sync="dialogdizhi" @close="closeDizhi" width="45%">
      <!-- 主体 -->
      <el-form ref="form" :model="Orderfrom" label-width="100px">
        <el-form-item required label="省市区/县" prop="order1" :rules="[{ required: true, message: '请选择地区', trigger: 'blur' }]">
          <el-cascader v-model="Orderfrom.order1" clearable :options="cityData" style="width:100%"></el-cascader>
        </el-form-item>
        <el-form-item label="详情地址" prop="order2" :rules="[{ required: true, message: '请输入详情地址', trigger: 'blur' }]">
          <el-input v-model="Orderfrom.order2"></el-input>
        </el-form-item>
      </el-form>
      <!-- 底部 -->
      <span slot="footer">
        <el-button @click="dialogdizhi=false">取消</el-button>
        <el-button type="primary" @click="BtnPutDizhi">
          提交
        </el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import Breadcrumbs from '@/components/Breadcrumbs'
import cityData from '../assets/js/citydata.js'
export default {
  name: 'Orders',
  data() {
    return {
      OrdersList: null,
      queryInfo: {
        query: '',
        pagenum: 1, //当前页数
        pagesize: 7, //每页显示多少条数据
      },
      total: 0,
      dialogdizhi: false,
      dialogwuliu: false,
      Orderfrom: {
        order1: [],
        order2: ''
      },
      cityData
    }
  },

  components: {
    Breadcrumbs,
  },
  created() {
    this.getOrders()
  },
  methods: {
    //监听pagesize改变事件
    handleSizeChange(newSize) {
      this.queryInfo.pagesize = newSize
      this.getOrders()
    },
    //监听 页码值 改变事件
    handleCurrentChange(newNum) {
      this.queryInfo.pagenum = newNum
      this.getOrders()
    },
    //获取数据
    getOrders() {
      this.$http.get('orders', { params: this.queryInfo }).then((res) => {
        console.log(res)
        if (res.data.meta.status !== 200) return
        this.OrdersList = res.data.data.goods
        this.total = res.data.data.total
        console.log(res.data.data.goods)
      })
    },
    closeDizhi() {  //关闭地址弹窗
      // console.log(this.$refs.form.resetFields)
      this.$refs.form.resetFields()
    },
    BtnWuliu() {
      this.$mess('接口已崩', 'warning')
    },
    BtnPutDizhi() {
      this.$refs.form.validate((res) => {
        if (res) {
          this.$mess('更新成功', 'success')
          this.dialogdizhi=false
        }
      })
    }
  },
}
</script>

<style>
</style>